/**
 * 
 */
package com.gwcloud.leetcode.hot100;

/**
 * @ClassName   : Leetcode0240 
 * @author      : ganwei 
 * @date        : 2020年5月22日
 * @Description : Leetcode0240 搜索二维矩阵 II
 */
public class Leetcode0240 {
    public boolean searchMatrix(int[][] matrix, int target) {
        if(matrix.length == 0){
        	return false;
        }
        int m = matrix.length;
        int n = matrix[0].length;
        for(int i = 0; i < m; i++){
        	for(int j = 0; j < n; j++){
        		if(matrix[i][j] == target){
        			return true;
        		}
        	}
        }
    	return false;
    }
    public boolean searchMatrix_1(int[][] matrix, int target){
    	int row = matrix.length;
    	int col = 0;
    	while(row >= 0 && col < matrix[0].length){
    		if(matrix[row][col] > target){
    			row--;
    		}else if(matrix[row][col] < target){
    			col++;
    		}else{
    			return true;
    		}
    	}
    	return false;
    }
}
